import request from "@/utils/request.js";

export function getUserByOpenId(openId) {
    return request.get(`/user?openId=${openId}`)
}

export function queryPatients(params) {
    return request.get(`/patient/page?page=${params.page}&pageSize=${params.pageSize}&name=${params.name}`)
}

export function listPatients() {
    return request.get(`/patient/list`)
}

export function getPatient(id) {
    return request.get(`/patient/${id}`)
}

export function createPatient(data) {
    return request.post('/patient', data)
}

export function updatePatient(data) {
    return request.put('/patient', data)
}

export function deletePatient(id) {
    return request.delete(`/patient/${id}`)
}

export function queryVision(params) {
    return request.get(`/patient/${params.patientId}/visions?page=${params.page}&pageSize=${params.pageSize}`)
}

export function getVision(id) {
    return request.get(`/vision/${id}`)
}

export function createVision(data) {
    return request.post(`/vision`, data)
}

export function updateVision(data) {
    return request.put(`/vision`, data)
}

export function deleteVision(id) {
    return request.delete(`/vision/${id}`)
}

export function getVisionChartData(size, patientId) {
    return request.get(`patient/${patientId}/vision/chart?size=${size}`)
}

export function getRemind(patientId) {
    return request.get(`remind/patient/${patientId}/remind`)
}

export function createRemind(data) {
    return request.post(`/remind`, data)
}

export function updateRemind(data) {
    return request.put(`/remind`, data)
}

export function getSnsToken(code) {
    return request.get( `/auth/openid?code=${code}`)
}

export function queryStatistic(params) {
    return request.get(`/vision/statistic?page=${params.page}&pageSize=${params.pageSize}&name=${params.name}`)
}

export const exportStatistic = (params) => {
    return request({
        url: `/vision/export?name=${params.name}`,
        method: "get",
        responseType: "blob" // 重要：设置响应类型为 blob
    })
}